package Engine;

import Entidades.Os;
import View.MainScreen;
import View.VerEndereco;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class Engine extends Thread {

    Os os = new Os();

    public void verifyChamados() throws InterruptedException {
        new Thread() {
            @Override
            public void run() {
                while (true) {
                    try {
                        sleep(5000);
                        try {
                            os.stautsChamadosAbertos();
                            os.stautsChamadosFechados();
                        } catch (SQLException ex) {
                            Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }.start();
    }

    public void carregaChamadosAbertos() {
        final Os _os_ref = new Os();
        final DefaultTableModel model = (DefaultTableModel) MainScreen.FinalizarChamadoTable.getModel();
        new Thread() {
            @Override
            public void run() {
                model.setRowCount(0);
                while (true) {
                    try {
                        sleep(30000);
                        model.setRowCount(0);
                        _os_ref.chamadosParaFinalizar();
                    } catch (InterruptedException | SQLException ex) {
                        JOptionPane.showMessageDialog(null, ex);
                    }
                }
            }
        }.start();
    }
}
